<template>
  <div>
    <div class="collect">
      <h1><i class="el-icon-s-management" />我的收藏</h1>
      <div class="box">
        <ul class="mi">
          <li v-for="item in list" :key="item.product_id">
              <i
                slot="reference"
                class="el-icon-close"
                @click='delCollect(item.product_id)'
              ></i>
            <img
              :src="'api' + item.product_picture"
              :alt="item.product_name"
              @click="pathAbout(item.product_id)"
            />
            <h3>{{ item.product_name }}</h3>
            <h4>{{ item.product_title }}</h4>
            <p>
              <span>{{ item.product_selling_price }}元</span>
              <s v-if="item.product_selling_price !== item.product_price"
                >{{ item.product_price }}元</s
              >
            </p>
            
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import collect from "../miAPI/getCollect";
export default {
  data() {
    return {
      list: [],
      visible:false,
    };
  },
  mounted() {
    this.getCollect();
  },
  methods: {
    // 进详情
    pathAbout(id) {
      this.$router.push("/about/details?id=" + id);
    },
    // 获取收藏列表的方法
    async getCollect() {
      var id = this.$store.state.user.user_id;
      let { data: res } = await collect.getCollect({ user_id: id });
      // console.log(res);
      this.list = res.collectList;
    },
    async delCollect(id) {
      let { data: res } = await collect.deleteCollect({
        user_id: this.$store.state.user.user_id,
        product_id: id,
      });
      // console.log(res)
      this.getCollect();
      if (res.code == "001") {
        this.$notify({
          type: "success",
          title: "成功",
          message: res.msg,
          duration: 3000,
        });
      } else if (res.code == "002") {
        this.$notify({
          type: "warning",
          title: "提示",
          message: res.msg,
          duration: 3000,
        });
      }
    },
  },
};
</script>

<style lang='scss'>
.collect {
  width: 100%;
  h1 {
    font-size: 40px;
    padding: 40px;
    border-bottom: 3px solid orange;
    padding: 0 8%;
  }
  .box {
    background: #f5f5f5;
    width: 100%;
    & > ul {
      width: 100%;
      display: flex;
      list-style: none;
      flex-wrap: wrap;
      li {
        background: #fff;
        width: 216px;
        height: 300px;
        margin: 0px 0 15px 10px;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        cursor: pointer;
        -webkit-transition: 0.5s;
        position: relative;
        .el-icon-close {
          position: absolute;
          top: 4px;
          right: 4px;
          opacity: 0;
        }
        h3 {
          width: 180px;
          font-size: 14px;
          color: #333;
          font-weight: 400;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          text-align: center;
        }
        h4 {
          font-size: 12px;
          color: #b0b0b0;
          font-weight: 400;
        }
        img {
          width: 160px;
          height: 160px;
          margin: 0 18px;
        }
        p {
          span {
            font-size: 16px;
            color: #ff6700;
          }
          s {
            display: inline-block;
            font-size: 16px;
            color: #b0b0b0;
            margin-left: 10px;
          }
        }
      }
      li:hover {
        transform: translateY(-2px);
        transition: all 0.5s;
        box-shadow: 0 10px 10px 4px rgb(221, 221, 221);
        .el-icon-close {
          opacity: 1;
        }
      }
    }
  }
}
</style>